package com.spring.boot.demo.controller;

import com.spring.boot.demo.master.mapper.EmpMapper;
import com.spring.boot.demo.pojo.DeptBo;
import com.spring.boot.demo.pojo.EmpBo;
import com.spring.boot.demo.slave.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/10/26 23:13
 * @Description
 */
@RestController
@RequestMapping("/api")
public class TestController {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private DeptMapper deptMapper;

    @GetMapping("/demo")
    public String demo() {
        // 查询所有员工信息
        List<EmpBo> empBoList = empMapper.queryAll();
        System.out.println(empBoList);
        // 查询每一个员工的部门信息
        for (EmpBo empBo : empBoList) {
            DeptBo deptBo = deptMapper.getDeptById(empBo.getDeptId());
            System.out.println(deptBo);
        }
        return "测试成功";
    }

}
